
import { defineStore } from 'pinia'
import type { User } from '@/types'
import { ref } from 'vue'

export const useUserStore = defineStore('user', () => {
  const user = ref<User>({
    id: '100',
    username: 'me',
    nickname: '我',
    avatar: '/images/avatars/me.jpg',
    signature: '个性签名',
    region: '中国'
  })

  const isLoggedIn = ref(true)

  const updateUser = (newUser: Partial<User>) => {
    Object.assign(user.value, newUser)
  }

  const logout = () => {
    isLoggedIn.value = false
    user.value = {} as User
  }

  return {
    user,
    isLoggedIn,
    updateUser,
    logout
  }
})
